/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyecto.so1;

import java.net.*;
import java.io.*;

/**
 *
 * @author antonio
 */
public class SendMSG extends Thread implements Runnable{
    private String text;
    private int port;
    
    
    public SendMSG(String msg){
        text = msg;
        port = 9999;
    }
    
    @Override
    public void run(){
        try{
            ServerSocket server = new ServerSocket(port, 0, NetworkInterface.getByName("eth0").getInterfaceAddresses().get(1).getAddress());
            server.setReuseAddress(true);
            System.out.println("Escuchando: "+server.toString());
            Socket client = server.accept();
            OutputStream output = client.getOutputStream();
            DataOutputStream data = new DataOutputStream(output);
            data.writeUTF(text);
            //client.setSoLinger(true, 3);
            client.close();
            server.close();
        }
        catch(Exception e){}
    }
    
}
